package com.android.rapidcash.activitys

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.android.lib.base.baseclass.BaseVMActivity
import com.android.lib.base.ext.click
import com.android.lib.base.manager.LiveBusManager
import com.android.lib.base.manager.MMKVManager
import com.android.rapidcash.viewmodel.MainViewModel
import com.blankj.utilcode.util.LanguageUtils
import com.rapidcash.abanca.santander.vivus.revolut.waylet.libertex.icmarkets.caixabank.R
import com.rapidcash.abanca.santander.vivus.revolut.waylet.libertex.icmarkets.caixabank.databinding.ActivityLanguageChangeBinding
import com.rapidcash.abanca.santander.vivus.revolut.waylet.libertex.icmarkets.caixabank.databinding.ActivityLoginBinding
import java.util.*

class LanguageChangeActivity : BaseVMActivity<MainViewModel, ActivityLanguageChangeBinding>() {
    private var isES = false

    override fun initView(savedInstanceState: Bundle?) {

    }

    override fun initData() {
        change()
    }

    override fun initListener() {
        mBinding.ivBack.click {
            finish()
        }
        mBinding.tv1.click {
            MMKVManager.encodeBoolean("LanguageES", true)
            change()
            LanguageUtils.applyLanguage(Locale.ENGLISH)
        }
        mBinding.tv2.click {
            MMKVManager.encodeBoolean("LanguageES", false)
            change()
            LanguageUtils.applyLanguage(LanguageUtils.getSystemLanguage())

        }
        mBinding.tv3.click {
            MMKVManager.encodeString("token", "")
            MMKVManager.encodeString("userID", "")
            MMKVManager.encodeString("isNew", "")
            MMKVManager.encodeString("phone", "")
            LiveBusManager.postInt("Login", 0)

            finish()
        }
    }


    private fun change() {
        if (MMKVManager.decodeBoolean("LanguageES", false)) {
            mBinding.tv1.setTextColor(Color.WHITE)
            mBinding.tv2.setTextColor(Color.parseColor("#fffe6b69"))
            mBinding.tv1.setBackgroundResource(R.mipmap.icon_lan_4)
            mBinding.tv2.setBackgroundResource(R.mipmap.icon_lan_5)
        } else {
            mBinding.tv2.setTextColor(Color.WHITE)
            mBinding.tv1.setTextColor(Color.parseColor("#fffe6b69"))
            mBinding.tv1.setBackgroundResource(R.mipmap.icon_lan_5)
            mBinding.tv2.setBackgroundResource(R.mipmap.icon_lan_4)
        }

    }
}